﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using eTerm.MsSql.DbProvider;
using eTerm.Platform.Common;

namespace eTerm.Platform.Web.PNR
{
    public partial class PNRHistory : BasePage
    {

        /// <summary>
        /// 页面初始化.
        /// </summary>
        protected override void InitPageLoad()
        {
            long ID = long.Parse(Request.Form["ID"]);
            rptDetr.DataSource = PnrHistory.All().Where(l => l.TicketNoId == ID).OrderBy(l => l.Id);
            rptDetr.DataBind();
        }

        /// <summary>
        /// Handles the OnItemDataBound event of the rptDetr control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RepeaterItemEventArgs" /> instance containing the event data.</param>
        protected void rptDetr_OnItemDataBound(object sender, RepeaterItemEventArgs e) {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                PnrHistory history = e.Item.DataItem as PnrHistory;
                Literal litSourceStatusName = e.Item.FindControl(@"litSourceStatusName") as Literal;
                Literal litNewStatusName = e.Item.FindControl(@"litNewStatusName") as Literal;
                LinkButton lnkView = e.Item.FindControl(@"lnkView") as LinkButton;
                Label lblResult = e.Item.FindControl(@"lblResult") as Label;
                lblResult.Text = (history.DetrInfo??string.Empty).Replace("\r", @"<br />").Replace("\n", @"<br />");
                litSourceStatusName.Text = EnumHelper.GetEnumName((DetrStatus)history.SourceStatusId);
                litNewStatusName.Text = EnumHelper.GetEnumName((DetrStatus)history.NewStatusId);
                lnkView.OnClientClick = string.Format(@"$.jBox.messager($('#{0}').html(), '指令信息', 0, {{width:650, showType: 'slide',icon:'info' }});return false;", lblResult.ClientID);
                lnkView.Visible = !string.IsNullOrEmpty(history.DetrInfo);
                BaseRegisterStartupScript<UpdatePanel>(GetUpdatePanel(@"pnlContent") as UpdatePanel, lnkView.ClientID, string.Format(@"$('#{0}').linkbutton({{   
    iconCls: 'icon-reload'  
}});  
", lnkView.ClientID), true);


            }
        }
    }
}
